import {
  reqGetAllCourseCategoryList,
  reqGetCourseList,
} from '@/pages/course/api/course.ts'
import { reqGetCourseListBody } from '@/pages/course/api/types/course'
import { reqGetLecturerData } from '@/pages/course/api/lecturer.ts'
import { respLecturerData } from '../api/types/lecturer'

export const useCourse = () => {
  // 获取课程分类全部列表
  const getAllCourseCategory = async () => {
    const resp = await reqGetAllCourseCategoryList()
    if (resp.code === 200 && resp.data) return resp.data
    return []
  }

  // 获取课程信息列表
  const getCourseList = async (reqData: reqGetCourseListBody) => {
    const resp = await reqGetCourseList(reqData)
    if (resp.code === 200 && resp.data) return resp.data.list
    return []
  }

  // 获取讲师信息
  const getLecturerData = async (id: string) => {
    const resp = await reqGetLecturerData(id)
    if (resp.code === 200 && resp.data) return resp.data
    return {} as respLecturerData
  }

  return { getAllCourseCategory, getCourseList, getLecturerData }
}
